*Replication data for:
*Owsiak, Andrew P. 2016. Foundations for integrating the democratic and territorial peace arguments. Conflict Management and Peace Science.

*NOTES
*a) This file replicates all tables in the manuscript file and appendix. These results from the analyses below also create the data underlying Figures 1 and A1.
*b) This file uses univar and spost9_ado packages; please install before continuing.
*c) Three data files are needed: "MID Onset.dta", "MIDs.dta", and "Crises.dta". Figures rely on "MID Graph Data.dta" and "Crisis Garph Data.dta."

use "MID Onset.dta", clear

set more off

*Description
tab conttype
tab settlem

univar midonset crisis jtdem6 settlem interaction majinvolve atopally lncincratio peaceyears crisispeace, dec(5)

tab midonset jtdem6, chi2 gamma
tab midonset settlem, chi2 gamma 
table midonset jtdem6 settlem, contents(freq) col row

tab crisis jtdem6, chi2 gamma
tab crisis settlem, chi2 gamma 
table crisis jtdem6 settlem, contents(freq) col row

tab settlem jtdem6, chi2 gamma
tab settlem jtdem6 if midonset==1, chi2 gamma
tab settlem jtdem6 if crisis==1, chi2 gamma


*Table 2 & A1.
*Model 1. Base model
logit midonset jtdem6 settlem interaction peaceyears _midspline1 _midspline2 _midspline3 if conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*Model 2. Main model, 1816-2001
logit midonset jtdem6 settlem interaction majinvolve atopally lncincratio peaceyears _midspline1 _midspline2 _midspline3 if conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*Model 3. Non-world war years, 1816-2001
logit midonset jtdem6 settlem interaction majinvolve atopally lncincratio peaceyears _midspline1 _midspline2 _midspline3 if worldwaryr==0 & conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*Model 4. 1900-2001
logit midonset jtdem6 settlem interaction majinvolve atopally lncincratio peaceyears _midspline1 _midspline2 _midspline3 if year>1900 & conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*Model 5. 1945-2001
logit midonset jtdem6 settlem interaction majinvolve atopally lncincratio peaceyears _midspline1 _midspline2 _midspline3 if year>1945 & conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)


*Crisis Onset
*Tables A2 & A3. 
*Model 1. Basic model
logit crisis jtdem6 settlem interaction crisispeace _crisspline1 _crisspline2 _crisspline3 if conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*Model 2. Main model, 1816-2001
logit crisis jtdem6 settlem interaction majinvolve atopally lncincratio crisispeace _crisspline1 _crisspline2 _crisspline3 if conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*Model 3. Non-world war years, 1816-2001
logit crisis jtdem6 settlem interaction majinvolve atopally lncincratio crisispeace _crisspline1 _crisspline2 _crisspline3 if worldwaryr==0 & conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*Model 4. 1945-2001
logit crisis jtdem6 settlem interaction majinvolve atopally lncincratio crisispeace _crisspline1 _crisspline2 _crisspline3 if year>1945 & conttype==1, cluster(cdyad)
prvalue, x(settlem=0 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=0 interaction=0) rest(mean) level(90)
prvalue, x(settlem=0 jtdem=1 interaction=0) rest(mean) level(90)
prvalue, x(settlem=1 jtdem=1 interaction=1) rest(mean) level(90)

*To create Figure 1/A1:
*1. Take predicted mean, c.i. bounds and enter into new dataset
use "MID Graph Data.dta", clear
graph twoway (scatter finalmean90 var1) (rcap finallow90 finalhigh90 var1)
use "Crisis Graph Data.dta", clear
graph twoway (scatter finalmean90 category) (rcap finallow90 finalhigh90 category)

*Table 3
*MIDS
use "MIDs.dta", clear
*MID Max Duration
ttest MaxDur if jtdem6==0, by(settlem)
ttest MaxDur if settlem==0, by(jtdem6)
ttest MaxDur if settlem==1, by(jtdem6)

*The severity of the disputes (using DG index) 
ttest severity if jtdem6==0, by(settlem)
ttest severity if settlem==0, by(jtdem6)
ttest severity if settlem==1, by(jtdem6)

*After border settlement, the highest action used by either disputants (max) falls.
ttest maxhiact if jtdem6==0 & cwmid==1, by(settlem)
ttest maxhiact if settlem==0 & cwmid==1, by(jtdem6)
ttest maxhiact if settlem==1 & cwmid==1, by(jtdem6)

*Crises
use "Crises.dta", clear
*Crises (brexit=duration in days)
ttest brexit if jtdem6==0, by(settlem)
ttest brexit if settlem==0, by(jtdem6)
ttest brexit if settlem==1, by(jtdem6)

*The severity of violence used within crises
ttest sevviosy if jtdem6==0, by(settlem)
ttest sevviosy if settlem==0, by(jtdem6)
ttest sevviosy if settlem==1, by(jtdem6)

*Crises are handled (negotiation, etc.) 
ttest crismg if jtdem6==0, by(settlem)
ttest crismg if settlem==0, by(jtdem6)
ttest crismg if settlem==1, by(jtdem6)

*After border settlement, crises less likely to have mediation.
ttest mediaterev if jtdem6==0, by(settlem)
ttest mediaterev if settlem==0, by(jtdem6)
ttest mediaterev if settlem==1, by(jtdem6)


*Table 4 & A5
use "MID Onset.dta", clear
tab icowclaim jtdem6, chi2 gamma
tab icowclaim jtdem6 if conttype==1, chi2 gamma
tab icowclaim jtdem6 if conttype!=1, chi2 gamma
tab maxresource jtdem6 if icowclaim==1, chi2 gamma
tab maxstratloc jtdem6 if icowclaim==1, chi2 gamma


*Table 5 & A4
*Model 1. Base model
logit midonset jtdem6 majinvolve atopally lncincratio peaceyears _midspline1 _midspline2 _midspline3 if conttype!=1, cluster(cdyad)
prvalue, x(jtdem=0) rest(mean) level(90)
prvalue, x(jtdem=1) rest(mean) level(90)

*Model 2. Main model, 1816-2001 (MODEL 2 in appendix)
logit midonset jtdem6 bothallsettle bothallsettleinteract majinvolve atopally lncincratio peaceyears _midspline1 _midspline2 _midspline3 if conttype!=1, cluster(cdyad)
prvalue, x(bothallsettle =0 jtdem=0 bothallsettleinteract=0) rest(mean) level(90)
prvalue, x(bothallsettle =1 jtdem=0 bothallsettleinteract =0) rest(mean) level(90)
prvalue, x(bothallsettle =0 jtdem=1 bothallsettleinteract =0) rest(mean) level(90)
prvalue, x(bothallsettle =1 jtdem=1 bothallsettleinteract =1) rest(mean) level(90)

*Model 3. Non-world war years, 1816-2001
logit midonset jtdem6 bothallsettle bothallsettleinteract majinvolve atopally lncincratio peaceyears _midspline1 _midspline2 _midspline3 if worldwaryr==0 & conttype!=1, cluster(cdyad)
prvalue, x(bothallsettle =0 jtdem=0 bothallsettleinteract=0) rest(mean) level(90)
prvalue, x(bothallsettle =1 jtdem=0 bothallsettleinteract =0) rest(mean) level(90)
prvalue, x(bothallsettle =0 jtdem=1 bothallsettleinteract =0) rest(mean) level(90)
prvalue, x(bothallsettle =1 jtdem=1 bothallsettleinteract =1) rest(mean) level(90)

*Model 4.
logit crisis jtdem6 majinvolve atopally lncincratio crisispeace _crisspline1 _crisspline2 _crisspline3 if conttype!=1, cluster(cdyad)
prvalue, x(jtdem=0) rest(mean) level(90)
prvalue, x(jtdem=1) rest(mean) level(90)

*Model 5
logit crisis jtdem6 bothallsettle bothallsettleinteract majinvolve atopally lncincratio crisispeace _crisspline1 _crisspline2 _crisspline3 if conttype!=1, cluster(cdyad)
prvalue, x(bothallsettle =0 jtdem=0 bothallsettleinteract=0) rest(mean) level(90)
prvalue, x(bothallsettle =1 jtdem=0 bothallsettleinteract =0) rest(mean) level(90)
prvalue, x(bothallsettle =0 jtdem=1 bothallsettleinteract =0) rest(mean) level(90)
prvalue, x(bothallsettle =1 jtdem=1 bothallsettleinteract =1) rest(mean) level(90)


*Table A6
*MIDs
use "MIDs.dta", clear
*MID Max Duration
ttest MaxDur if conttype!=1, by(jtdem6)
ttest MaxDur if jtdem6==0 & conttype!=1, by(bothallsettle)
ttest MaxDur if bothallsettle==0 & conttype!=1, by(jtdem6)

*The severity of the disputes (using DG index) 
ttest severity if conttype!=1, by(jtdem6)
ttest severity if jtdem6==0 & conttype!=1, by(bothallsettle)
ttest severity if bothallsettle==0 & conttype!=1, by(jtdem6)

*After border settlement, the highest action used by either disputants (max) falls.
ttest maxhiact if conttype!=1 & cwmid==1, by(jtdem6)
ttest maxhiact if jtdem6==0 & conttype!=1 & cwmid==1, by(bothallsettle)
ttest maxhiact if bothallsettle==0 & conttype!=1 & cwmid==1, by(jtdem6)

*Crises
use "Crises.dta", clear
*Crises (brexit=duration in days)
ttest brexit if conttype!=1, by(jtdem6)
ttest brexit if jtdem6==0 & conttype!=1, by(bothallsettle)
ttest brexit if bothallsettle==0 & conttype!=1, by(jtdem6)


*The severity of violence used within crises
ttest sevviosy if conttype!=1, by(jtdem6)
ttest sevviosy if jtdem6==0 & conttype!=1, by(bothallsettle)
ttest sevviosy if bothallsettle==0 & conttype!=1, by(jtdem6)

*Crises are handled (negotiation, etc.) 
ttest crismg if conttype!=1, by(jtdem6)
ttest crismg if jtdem6==0 & conttype!=1, by(bothallsettle)
ttest crismg if bothallsettle==0 & conttype!=1, by(jtdem6)

*After border settlement, crises less likely to have mediation.
ttest mediaterev if conttype!=1, by(jtdem6)
ttest mediaterev if jtdem6==0 & conttype!=1, by(bothallsettle)
ttest mediaterev if bothallsettle==0 & conttype!=1, by(jtdem6)

